//
//  PublishSubjectViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/25.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxSwift

class PublishSubjectViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        self.view.addTapWithHandle { (tap) in
            
            let disBag = DisposeBag()
            
            // PublishSubject只会发送给订阅者订阅之后的事件，之前发生的事件将不会发送。
            let subject = PublishSubject<String>()
            
            subject.subscribe({ (eve) in
                print("1 \(eve)")
            }).disposed(by: disBag)
            
            subject.onNext("11")
            subject.onNext("12")
            
            subject.subscribe({ (eve) in
                print("2 \(eve)")
            }).disposed(by: disBag)
            
            subject.onNext("21")
            subject.onNext("22")
            
        }
        
    }
}
